"""
客户门户API路由
"""

from fastapi import APIRouter, HTTPException
from typing import Dict, Any

from models.portal_models import CustomerPortalRequest
from managers.stripe_manager import StripeManager
from managers.portal_manager import PortalManager

router = APIRouter(tags=["客户门户"])

# 创建全局的管理器实例
stripe_manager = StripeManager()
portal_manager = PortalManager(stripe_manager.customer_service)


@router.post("/api/create-portal-session")
async def create_portal_session(request: CustomerPortalRequest):
    """创建 Customer Portal 会话"""
    return portal_manager.create_portal_session(request.customer_id, request.return_url)


@router.get("/portal-return")
async def portal_return():
    """Customer Portal 返回页面"""
    return portal_manager.get_portal_return_info()


@router.get("/subscription/success")
async def subscription_success(session_id: str):
    """订阅支付成功页面"""
    return stripe_manager.handle_subscription_success(session_id)


@router.get("/subscription/cancel")
async def subscription_cancel():
    """订阅支付取消页面"""
    return portal_manager.get_subscription_cancel_info()
